package priv.zgh.forum.re.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.StringUtils;
import priv.zgh.forum.re.entity.ResourcesGame;
import priv.zgh.forum.re.entity.ResourcesSimulator;
import priv.zgh.forum.re.mapper.ResourcesGameMapper;
import priv.zgh.forum.re.service.ResourcesGameService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZGH
 * @since 2022-04-21
 */
@Service
public class ResourcesGameServiceImpl extends ServiceImpl<ResourcesGameMapper, ResourcesGame> implements ResourcesGameService {

    @Override
    public Page<ResourcesGame> pageResourcesConditionByType(long current, long limit, ResourcesGame query) {
        Page<ResourcesGame> page = new Page<>(current,limit);
        QueryWrapper<ResourcesGame> wrapper = new QueryWrapper<>();
        //取出查询封装的数据
        String resourcesName = query.getName();
        //拼接动态SQL语句
        if(!StringUtils.isEmpty(resourcesName)){
            //构建条件
            wrapper.like("name",resourcesName);
        }
        //根据创建时间排序
        wrapper.orderByDesc("gmt_create");
        //将条件wrapper封装进service进行查询,然后将放回的结果封装进page
        baseMapper.selectPage(page,wrapper);
        return page;
    }
}
